package
{
	import flash.display.DisplayObjectContainer;
	import flash.display.Stage;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	import newx.StageInfo;
	import newx.com.config.StaticIni;
	import newx.utils.debug.IO;

	/**
	 * 加载器代理类 
	 * @author guyi
	 * 
	 */	
	public class NxLoaderProxy
	{
		
		public function NxLoaderProxy()
		{
		}
		
		static public var _loginProgress:*;
		/**30*/
		static public const proBarS:int	=	30;
		/**10*/
		static public const proBarW:int	=	10;
		/**40*/
		static public const loginUIS:int	=	40;
		/**20*/
		static public const loginUIW:int	=	20;
		/**60*/
		static public const configDataS:int	=	60;
		/**20*/
		static public const configDataW:int	=	20;
		/**80*/
		static public const uiDataS:int	=	80;
		/**20*/
		static public const uiDataW:int	=	20;
		/**90*/
//		static public const createUIS:int	=	99;
		/**10*/
//		static public const createUIW:int	=	1;
		/**100*/
		static public const complete:int	=	100;
	 	/***TipSTimer**/
		static public var _timer:Timer;
		
		static public function init(stage:Stage):void
		{
			
			try
			{
				var _loader:*	=	stage.getChildAt(1);
				_loginProgress	=	_loader._loginProgress;
			}
			catch(e:*)
			{
				IO.traceLog("非壳加载");
			}
		}
		
		
		/**
		 * 30加载游戏1M
		 * 40游戏加载进度条
		 * 50游戏加载登录部分或者不加载//
		 * 60游戏加载ConfigData.swf
		 * 80游戏加载ui.swf,等几个资源
		 * 100游戏初始化UI			
		 * 
		 * 完成.显示登录界面或者直接进入游戏
		 * 
		 * @param per
		 * @param title
		 * 
		 */		
		static public function setProgress(per:int,title:String="",show:Boolean=false):void
		{
			if(	null	!=	_loginProgress)
			{
				_loginProgress.setPer(per,title);
				
				if(show)
					_loginProgress.setTips(title);
			}
		}
		
		/**
		 *设置小提示 
		 * 
		 */
		static private function setTipsLabel():void
		{
			if(!_timer)
			{
				_timer = new Timer(2000)
				_timer.addEventListener(TimerEvent.TIMER,onTimerHandle);
				_timer.start();
			}
		}
		
		/**
		 *移除小提示TIMER 
		 * 
		 */
		static private function removeTipsTimer():void
		{
			if(_timer)
			{
				_timer.reset();
				_timer.stop();
				_timer.removeEventListener(TimerEvent.TIMER,onTimerHandle);
				_timer = null;
			}
		}
		
		static private function onTimerHandle(e:TimerEvent):void
		{
			var tips:String	=	getTip();
			if(""	!=	tips)
			{
				_loginProgress.setTips(tips);
			}
		}
		
		static private function getTip():String
		{
			var str:String	=	"";
			
			var tipsObj:Object	=	StaticIni.getIniObj("SwitchSceneTips");
			
			if(null		!=	tipsObj)
			{
				var num:int			=	tipsObj.num;
				var randomId:int	=	Math.round((num-1)*Math.random())	;
				str		=	StaticIni.getSwfLangStr(tipsObj["tips"+randomId]);
			}			
			return	str;
		}
		
		static public function show(container:DisplayObjectContainer = null):void
		{
			if(	null	!=	_loginProgress)
			{
				if(null	==	container)	container	=	StageInfo.systemSpace;
				
				_loginProgress.show(container);
				
//				_loginProgress.x	=	100;
				
				var tips:String	=	getTip();
				
				if(""	!=	tips)
				{
					_loginProgress.setTips(tips);
				}
			}
		}
		
		
		static public function hide():void
		{
			if(	null	!=	_loginProgress)
			{
				_loginProgress.hide();	
			}	
		}
		
		static public function setVisible(val:Boolean):void
		{
			if(null	!=	_loginProgress)
			{
				_loginProgress.visible	=	val;
			}
//			if(val)
//			{
//				setTipsLabel();
//			}else
//			{
//				removeTipsTimer();
//			}
		}
		
	}
}